﻿#region License
/* ---------------------------------------------------------------- *
 *
 * This file is part of the Xcoordination Application Space
 * ("XcoAppSpace") http://www.xcoordination.com
 *
 * Copyright (C) 2009 Xcoordination http://www.xcoordination.com
 *
 * XcoAppSpace is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General
 * Public License as published by the Free Software Foundation.
 *
 * XcoAppSpace is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/
 * or write to the Free Software Foundation, Inc., 51 Franklin
 * Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * ---------------------------------------------------------------- */
#endregion

using System;
using System.Collections.Generic;
using System.Linq;

namespace XcoAppSpaces.Core.Ports.Remoting
{
	/// <summary>
	/// Infomation about a Port concerning remote communication.
	/// </summary>
	public class XcoPortInfo
	{
		/// <summary>
		/// True if the port is a remote port.
		/// </summary>
		public bool IsRemotePort { get; private set; }

		/// <summary>
		/// The remote address where the port is hosted, or null if the port is local.
		/// </summary>
		public string RemoteAddress { get; set; }

		/// <summary>
		/// The type of remote port (worker proxy or "normal" remote port).
		/// </summary>
		public RemotePortType RemotePortType { get; set; }

		/// <summary>
		/// The id of the port. The value is Guid.Empty if the port is local, of if it is a worker proxy.
		/// </summary>
        public Guid RemotePortID { get; set; }

		/// <summary>
		/// The worker identifier, if the port is a worker proxy.
		/// </summary>
		public string WorkerIdentifier { get; set; }

		/// <summary>
		/// The session id, if the port is a worker proxy. The session id is only set, if a security service is used that uses sessions.
		/// </summary>
		public Guid SessionID { get; set; }

		/// <summary>
		/// The name of the transport service that the port uses, or null if the port is local.
		/// </summary>
        public string TransportServiceName { get; internal set; }


		/// <summary>
		/// Creates a new XcoPortInfo. This constructor if for "normal" remote ports.
		/// </summary>
		/// <param name="isRemotePort">True if the port is a remote port.</param>
		/// <param name="remoteAddress">The remote address where the port is hosted, or null if the port is local.</param>
		/// <param name="transportServiceName">The name of the transport service that the port uses, or null if the port is local.</param>
		/// <param name="remotePortID">The id of the port, or Guid.Empty if the port is local.</param>
        public XcoPortInfo(bool isRemotePort, string remoteAddress, string transportServiceName, Guid remotePortID)
        {
            this.IsRemotePort = isRemotePort;
            this.RemoteAddress = remoteAddress;
			this.TransportServiceName = transportServiceName;
            this.RemotePortID = remotePortID;
			this.RemotePortType = RemotePortType.RemotePort;
        }

		/// <summary>
		/// Creates a new XcoPortInfo. This constructor if for worker proxies.
		/// </summary>
		/// <param name="isRemotePort">True if the port is a remote port.</param>
		/// <param name="remoteAddress">The remote address where the port is hosted, or null if the port is local.</param>
		/// <param name="transportServiceName">The name of the transport service that the port uses, or null if the port is local.</param>
		/// <param name="workerIdentifier">The worker identifier, if the port is a worker proxy.</param>
		/// <param name="sessionID">The session id, if the port is a worker proxy. The session id is only set, if a security service is used that uses sessions.</param>
		public XcoPortInfo(bool isRemotePort, string remoteAddress, string transportServiceName, string workerIdentifier, Guid sessionID)
		{
			this.IsRemotePort = isRemotePort;
			this.RemoteAddress = remoteAddress;
			this.TransportServiceName = transportServiceName;
			this.WorkerIdentifier = workerIdentifier;
			this.SessionID = sessionID;
			this.RemotePortType = RemotePortType.WorkerProxy;
		}
	}
}
